package com.czy.owner.api;

import com.czy.owner.db.UserHelper;
import com.czy.owner.global.Constants;
import com.czy.owner.net.api.BaseApi;
import com.czy.owner.net.listener.HttpOnNextListener;
import com.trello.rxlifecycle.components.support.RxAppCompatActivity;

import java.util.HashMap;

import retrofit2.Retrofit;
import rx.Observable;

/**
 * Created by wangyang on 2017/5/12 0012.
 */

public class OwnerStoreBespokeApi extends BaseApi {

    private String storeId;
    private String session;
    private String gprsX;
    private String gprsY;

    public OwnerStoreBespokeApi(HttpOnNextListener listener, RxAppCompatActivity rxAppCompatActivity) {
        super(listener, rxAppCompatActivity);
        setShowProgress(true);
        setCache(true);
        setMothed(UserHelper.getInstance().getUserAccount() + Constants.OWN_BRANCHSTORE);//相当于缓存保存的Key
        setCookieNetWorkTime(0);//有网缓存0s,在0s内点击无效
        setCookieNoNetWorkTime(24 * 60 * 60 * 7);//无网缓存7天
    }

    public void setProgress(boolean bool) {
        setShowProgress(bool);
    }

    public String getSession() {
        return session;
    }

    public void setSession(String session) {
        this.session = session;
    }

    public String getGprsX() {
        return gprsX;
    }

    public void setGprsX(String gprsX) {
        this.gprsX = gprsX;
    }

    public String getGprsY() {
        return gprsY;
    }

    public void setGprsY(String gprsY) {
        this.gprsY = gprsY;
    }

    public String getStoreId() {
        return storeId;
    }

    public void setStoreId(String storeId) {
        this.storeId = storeId;
    }

    /**
     * * session 登录返回session 必填
     * gprsX 手机端获取到的经度坐标
     * gprsY 手机端获取到的纬度坐标
     * storeId 门店ID 必填
     * storeName
     */
    @Override
    public Observable getObservable(Retrofit retrofit) {
        HttpPostService service = retrofit.create(HttpPostService.class);
        HashMap<String, Object> map = new HashMap<>();
        map.put("storeId", getStoreId());
        map.put("gprsX", getGprsX());
        map.put("gprsY", getGprsY());
        map.put("session", getSession());
        return service.getBranchStoreApi(map);
    }
}
